﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 图片裁剪压缩工具
{
    public class ConstSizeCutEvent : IRectEvent
    {
        public int TargetWidth { get; }
        public int TargetHeight { get; }

        private Point p;
        private bool isMouseDown = false;

        public ConstSizeCutEvent(int targetWdith=100,int targetHeight = 100)
        {
            this.TargetWidth = targetWdith;
            this.TargetWidth = targetHeight;
        }
        public void MouseDown(object? sender, MouseEventArgs e)
        {
            p.X = e.X;
            p.Y = e.Y;
            isMouseDown = true;
        }

        public void MouseLeave(object? sender, EventArgs e)
        {
            isMouseDown = false;
        }

        public void MouseMove(object? sender, MouseEventArgs e)
        {
            var lCtrl = (sender as RectView);

            if (e.Button == MouseButtons.Left)
            {
                if (isMouseDown)
                {
                    lCtrl.Left = lCtrl.Left + e.X - p.X;
                    lCtrl.Top = lCtrl.Top + e.Y - p.Y;
                }
                p = e.Location;
                lCtrl.NotifPaint();
            }
        }

        public void MouseUp(object? sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }
    }
}
